<?php
/**
 * Created by PhpStorm.
 * User: DELL
 * Date: 2018/2/25
 * Time: 15:03
 */

namespace app\home\controller;
use app\home\model\Gate;
use app\home\model\Good as GoodModel;
/**
 * Class Good
 * @package app\home\controller
 * 成功学员
 */
class Good extends  Base
{
    /*
     * 首页
     */
    public function index(){
        $this->jssdk();
        // 筛选列表
        $deps = GoodModel::where([])->group('certi_name')->column('certi_name');
        if ($deps){
            foreach($deps as $key => $value){
                $deps[$key] = iconv("gbk", "utf-8//ignore", $value);
            }
            $this->assign('name',$deps[0]);
            $where = iconv("utf-8", "gbk//ignore", $deps[0]);
        }else{
            $this->assign('name','暂无');
            $where = '';
        }
        $list = GoodModel::where('certi_name',$where)->order('id','asc')->limit(20)->select();  // 获取 成功学员列表
        foreach($list as $key => $value){
            $list[$key]['name'] = iconv("gbk", "utf-8//ignore", $value['name']);
        }
        $this->assign('deps',$deps);
        $this->assign('list',$list);
        return $this ->fetch();
    }
    /*
     * 筛选
     */
    public function select(){
        $id = input('id');
        $map = iconv("utf-8", "gbk//ignore", $id);
        $list = GoodModel::where('certi_name',$map)->order('id','asc')->limit(20)->select();           // 获取 用户列表
        $arr = [];
        foreach($list as $key => $value){
            $arr[$key]['name'] = iconv("gbk", "utf-8//ignore", $value['name']);
            $arr[$key]['id'] = $value['id'];
            $arr[$key]['certi_achi'] = $value['certi_achi'];
        }
        if ($arr){
            return ['code' => 1,'data' => $arr];
        }else{
            return ['code' => 0,'data' => ''];
        }
    }
    /*
     * 加载更多
     */
    public function more(){
        $len = input('length/d');
        $id = input('id');
        $map =iconv("utf-8", "gbk//ignore", $id);
        $list = GoodModel::where('certi_name',$map)->order('id','asc')->limit($len,20)->select();  // 获取 用户列表
        $arr = [];
        foreach($list as $key => $value){
            $arr[$key]['name'] = iconv("gbk", "utf-8//ignore", $value['name']);
            $arr[$key]['id'] = $value['id'];
            $arr[$key]['certi_achi'] = $value['certi_achi'];
        }
        if ($arr){
            return ['code' => 1,'data' => $arr];
        }else{
            return ['code' => 0,'data' => ''];
        }
    }
    /*
     * 详情
     */
    public function detail(){
        $this->jssdk();
        $id = input('id/d');
        $info = GoodModel::where(['id' => $id])->find();
        if (empty($info) || empty($id)){
            $this->redirect('Journal/del');
        }
        $Gate = Gate::where(['id' => $info['project_id']])->find();
        $info['class1'] = $Gate['class1'];
        $info['class2'] = $Gate['class2'];
        $info['class3'] = $Gate['class3'];
        $info['class4'] = $Gate['class4'];
        if ($info['certi_file']){
            $info['img'] = 'http://www.popedu.net/data/'.iconv("gbk", "utf-8//ignore", $info['certi_file']);
        }else{
            $info['img'] = '';
        }
        $this->assign('msg',$info);
        return $this->fetch();
    }
}